/*
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 */
function onAddNewProject(frmID, msgDiv, listtable) {
	var newId = '';
	var linkto = '';
	$(frmID).request( {
			asynchronous: false,
			parameters: $(frmID).serialize(true),
	  	onComplete: function(transport) { 
			  var response = transport.responseText || "";
				var pos=response.indexOf('<!');
				content=response.substring(0,pos);
		    	
		    	if(content != "") {
		    		obj = content.evalJSON();
		    		if(msgDiv != null)
				    	$(msgDiv).update(obj.message);
					   if(obj.linkactive!=null)
						    linkto = obj.linkactive;
		    		if(obj == null) {
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + response);
		    		}
		    	}
	  	}
	});
	if(linkto!="")
		document.location = linkto;
	else {
		$(msgDiv).style.display = 'block';
		Fat.fade_element(msgDiv, null, 1500, null, null);
		if(newId != '')
			Fat.fade_element(newId);
		return false;
	}
}

function onDeleteProject(url, ProjectId, resp) {
	var isOK = -1;
	if(!confirm('Are you sure you want to delete the Project with Id:' + ProjectId)) {
		return false;
	}
	
	new Ajax.Request(url, {
	  method: 'POST',
	  asynchronous: false,
	  parameters:'act=delproject&id=' + ProjectId,
	  onSuccess: function(transport) {
			var response = transport.responseText || "";
			var pos=response.indexOf('<!');
			content=response.substring(0,pos);
			obj = content.evalJSON();

    		if(obj == null) {
    			$(resp).innerHTML = 'Something wrong! Reponsed string is: ' + response;
    		}
    		
    		isOK = obj.code;
		
    		$(resp).update(obj.message);
		}
	});

	$(resp).style.display = 'inherit';
	Fat.fade_element(resp, null, 1500, null, null);

	if(isOK == 0){
		rowID = 'project-' + ProjectId;
		Fat.fade_element(rowID, null, 1000, "#f22", null);
		setTimeout("$(rowID).remove()", 1000);
		
	}				
}


function onEditProject(frmID, msgDiv) {
	var newId = '';
	var status = null;
	var ret = null;
	var message = null;
	var linkto = '';
	$(frmID).request( {
			asynchronous: false,
			parameters: $(frmID).serialize(true),
	  	onComplete: function(transport) { 
			   var response = transport.responseText || "";
				 var pos=response.indexOf('<!');
				 content=response.substring(0,pos);

		    	if(content != "") {
		    		obj = content.evalJSON();
		    		if(obj == null) {
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + response);
		    		}
		    		
            if(msgDiv != null)
            	$(msgDiv).update(obj.message);
            if(obj.project_id==0) {
              ret =1;	
              message = obj.msg;
            }
					  if(obj.linkactive!=null)
					    linkto = obj.linkactive;
		      }
	  		}
	});
	if(linkto!="") {
      document.location = linkto;
	} else {
	   $(msgDiv).style.display = 'block';
	   Fat.fade_element(msgDiv, null, 1500, null, null);
	}
	return false;
}